package ysc.cqnu.operdb.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ysc.cqnu.operdb.entity.ReceiveUserInfo;
import ysc.cqnu.operdb.entity.ResultData;
import ysc.cqnu.operdb.entity.ResultUserInfo;
import ysc.cqnu.operdb.entity.User;
import ysc.cqnu.operdb.mapper.UserMapper;
import ysc.cqnu.operdb.service.UserLoginService;

@Component
public class UserLoginServiceImpl implements UserLoginService {
    @Autowired
    private UserMapper userLoginMapper;
    @Autowired
    private User user;
    @Autowired
    private ResultData resultData;
    @Autowired
    private ResultUserInfo resultLogin;
    @Override
    public ResultData isLogin(ReceiveUserInfo receiveLogin) {
        user = userLoginMapper.findByName(receiveLogin.getName());
        if(user==null){
            resultData.flag="noName";
            resultData.data=null;
            return resultData;
        }
        if(!receiveLogin.getPassword().equals(user.getPassword())){
            resultData.flag="passwordError";
            resultData.data=null;
            return resultData;
        }
        resultData.flag="success";
        resultLogin.id=String.valueOf(user.getId());
        resultLogin.name=user.getName();
        resultLogin.emile=user.getEmile();
        resultLogin.age=user.getAge();
        resultLogin.sex=user.getSex();
        resultLogin.userType=user.getUserType();
        resultLogin.userImgSrc=user.getUserImgSrc();
        resultLogin.recordDdate=user.getRecordDdate();
        resultData.data=resultLogin;
        return resultData;
    }
}
